﻿//
//  HFHttpPushExtensionFactory.m
//  HFBaseHTTPRequestManagerModule
//
//  Created by Points on 2020/5/7.
//

#import "HFHttpPushExtensionFactory.h"

@implementation HFHttpPushExtensionFactory

- (id<HFHttpAbstractFactory> (^)(NSString *))setPath{
    __weak typeof(self) weakSelf = self;
    return ^(NSString *path){
        weakSelf.mPath = path;
        return weakSelf;
    };
}

- (id<HFHttpAbstractFactory> (^)(void))post{
      __block __weak typeof(self) weakSelf = self;
     return ^(void){
         if (self.rsaEncryptResult) {
             BOOL needToast = weakSelf.needToast;
             BOOL rsaSwitch = weakSelf.rsaSwitch;
             HFHttpSucceedBlock successBlock = weakSelf.mSucceedBlock;
             HFHttpFailedBlock failBlock = weakSelf.mFailedBlock;
             NSURLSessionTask *task = [HFBaseHTTPRequestManager HTGET:weakSelf.mPath parameters:weakSelf.mPara success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
                 [HFHttpPushExtensionFactory requestSuccessWithTask:task
                                                                body:weakSelf.mPara
                                                responseObject:responseObject
                                                successHandler:successBlock
                                                     needToast:needToast
                                                     rsaSwitch:rsaSwitch];
             } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
                 [HFHttpPushExtensionFactory requestFailureWithTask:task
                                                               param:weakSelf.mPara
                                                               error:error
                                                      failureHandler:failBlock
                                                           needToast:needToast];
             }];
             [weakSelf startDelayTimer:task];
         }
         return weakSelf;
     };
}

@end

